package mk.company.fin.model;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
//import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
//import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import mk.company.fin.FinConstants;
import mk.company.fin.enums.NalogEntryType;

@Entity
@Table(name = FinConstants.Tables.NALOG_ENTRY)
public class NalogEntry extends Model {

	private static final long serialVersionUID = 6411585097017666394L;

	// persistent
	private Long id;
	private NalogEntryType type;
	private Konto konto;
	private BigDecimal amount;
	private String description;
//	private Document document;
	private String documentNumber;
	private Date documentDate;
	private Date valuta;
	private Komintent komintent;
	private OrganizationSector organizationSector;
	private Nalog nalog;
//	private Date entryDate;
	
	
	
	
	@Id
	@Column(name = "id_nalog_entry")
	//@SequenceGenerator(name = "nalogentry_seq", sequenceName = "nalogentry_seq", allocationSize = 1)
	@GeneratedValue//(strategy = GenerationType.SEQUENCE, generator = "nalogentry_seq")
	public Long getId() {
		return id;
	}
	
	public Date getDocumentDate() {
		return documentDate;
	}

	public void setDocumentDate(Date documentDate) {
		this.documentDate = documentDate;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@Enumerated(value = EnumType.STRING)
	public NalogEntryType getType() {
		return type;
	}

	public void setType(NalogEntryType type) {
		this.type = type;
	}

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "id_konto", nullable = false)
	public Konto getKonto() {
		return konto;
	}

	public void setKonto(Konto konto) {
		this.konto = konto;
	}

	@Column(nullable = false, precision = 15, scale = FinConstants.Application.NUMBER_SCALE)
	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	@Column
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

//	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
//	@JoinColumn(name = "id_document")
//	public Document getDocument() {
//		return document;
//	}
//
//	public void setDocument(Document document) {
//		this.document = document;
//	}

	@Column
	public String getDocumentNumber() {
		return documentNumber;
	}

	public void setDocumentNumber(String documentNumber) {
		this.documentNumber = documentNumber;
	}

//	s

	@Column
	public Date getValuta() {
		return valuta;
	}

	public void setValuta(Date valuta) {
		this.valuta = valuta;
	}

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "id_komintent")
	public Komintent getKomintent() {
		return komintent;
	}

	public void setKomintent(Komintent komintent) {
		this.komintent = komintent;
	}

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "id_organization_sector", nullable = false)
	public OrganizationSector getOrganizationSector() {
		return organizationSector;
	}

	public void setOrganizationSector(OrganizationSector organizationSector) {
		this.organizationSector = organizationSector;
	}
	
	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "id_nalog", nullable = false)
	public Nalog getNalog() {
		return nalog;
	}

	public void setNalog(Nalog nalog) {
		this.nalog = nalog;
	}
	

	
	/**
	 * @return how much is the "dolzi" part
	 */
	@Transient
	public BigDecimal getDolzi() {
		return NalogEntryType.DOLZI.equals(getType()) ? getAmount() : BigDecimal.ZERO;
	}
	
	@Deprecated
	public void setDolzi(BigDecimal dolzi) {
		throw new UnsupportedOperationException("The field dolzi is dynamic!");
	}
	
	/**
	 * @return how much is the "pobaruva" part
	 */
	@Transient
	public BigDecimal getPobaruva() {
		return NalogEntryType.POBARUVA.equals(getType()) ? getAmount() : BigDecimal.ZERO;
	}
	
	@Deprecated
	public void setPobaruva(BigDecimal pobaruva) {
		throw new UnsupportedOperationException("The field pobaruva is dynamic!");
	}

//	public void setEntryDate(Date entryDate) {
//		this.entryDate = entryDate;
//	}
//	
//	@Column
//	public Date getEntryDate() {
//		return entryDate;
//	}

}
